package com.example.manager;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.example.manager.javaBean.GsonBean;
import com.example.manager.retrofit.ApiService;
import com.example.manager.Utils.RetrofitManager;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ApiService apiService = RetrofitManager.getApiService();

        apiService.getNewType1().enqueue(new Callback<GsonBean>() {
            @Override
            public void onResponse(Call<GsonBean> call, Response<GsonBean> response) {
                if (response.isSuccessful()) {
                    GsonBean gsonBean = response.body();
                    if (gsonBean != null && gsonBean.data != null) {
                        for (GsonBean.Data data : gsonBean.data) {
                            Log.d("新闻信息", "Name: " + data.name + ", ID: " + data.id);
                            // 还可以根据需要输出其他字段
                        }
                    } else {
                        Log.e("新闻信息", "响应数据为空");
                    }
                } else {
                    Log.e("新闻信息", "请求失败，错误码：" + response.code());
                }
            }

            @Override
            public void onFailure(Call<GsonBean> call, Throwable throwable) {
                System.out.println("aaaa");
                Log.e("新闻信息", "请求失败", throwable);
                System.out.println("aaaa: " + throwable.getMessage());
            }
        });
    }
}